#include "Histogram.h"
namespace LightChart {
Histogram::Histogram(QWidget * parent) : BasicHistogram(), BasicHistogramGUI(parent) {
}
void Histogram::draw() {
    PlotWindow * plotWindow = new PlotWindow(parentWidget());
    qwtHistogram adapter(*this);
    adapter.preparePlot(plotWindow->get_plot());
    plotWindow->show();
}
void Histogram::showOptions() {
    show();
    try {
        title = lineEditTitle->text().toStdString();
        bgColor = get_color();
        if(!lineEditWidth->text().isEmpty()) {
            double tmp = QStringToDouble(lineEditWidth->text());
            if(tmp < 100 || tmp > 1920) throw std::runtime_error("Wrong width specified. Width must be in [100 : 1920]");
            else windowWidth = tmp;
        }
        if(!lineEditHeight->text().isEmpty()) {
            double tmp = QStringToDouble(lineEditHeight->text());
            if(tmp < 50 || tmp > 1080) throw std::runtime_error("Wrong height specified. Height must be in [50 : 1080]");
            else windowHeight = tmp;
        }
        if(!lineEditMin->text().isEmpty()) {
            min = QStringToDouble(lineEditMin->text());
        }
        if(!lineEditMax->text().isEmpty()) {
            max = QStringToDouble(lineEditMax->text());
        }
    }
    catch(const std::runtime_error& e) {
        QMessageBox::critical(this,"Input data corrupted.",e.what());
    }
}
void Histogram::restoreGlobalSettings() {
    const GlobalChartSettings& globalSettings = GlobalChartSettings::get_instance();
    title = globalSettings.chartTitle;
    windowWidth = globalSettings.width;
    windowHeight = globalSettings.height;
    bgColor = globalSettings.bgColor;
}
}
